package cn.afactory.tygz.ui.base.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import cn.afactory.tygz.R;
import cn.afactory.tygz.model.SnsCommentInfo;
import cn.afactory.tygz.ui.base.utils.sns.CommentTextUtil;

/**
 * 首页评论Adapter
 * xiezhidong251@jk.cn
 */
public class CommentItemadapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    List<SnsCommentInfo> mInfos = new ArrayList<SnsCommentInfo>();

    public CommentItemadapter(Context context, List<SnsCommentInfo> infos) {
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mInfos = infos;
    }

    public void setData(List<SnsCommentInfo> infos) {
        this.mInfos = infos;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mInfos == null ? 0 : this.mInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return mInfos == null ? null : this.mInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_base_list, null);
            viewHolder.tv_listitem = (TextView) convertView.findViewById(R.id.tv_listitem);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
//        if (mInfos.get(pos        ition).id > 0 || !TextUtils.isEmpty(mInfos.get(position).textContent)) {
//            CommentTextUtil.setTextView(mContext, viewHolder.tv_listitem, mInfos.get(position), true);
//        } else {
//            viewHolder.tv_listitem.setVisibility(View.GONE);
//        }

        return convertView;
    }

    private static class ViewHolder {
        TextView tv_listitem;
    }
}
